using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace ArtificialIntelligence.Racing
{
    public class ControlPlayer
    {
        KeyboardState KeySt;
        Sound Sound;
        RacePlayer _player;
        City _city;
        Game _game;
        public ControlPlayer(RacePlayer player, City city, Game game)
        {
            this._player = player;
            this._city = city;
            this._game = game;
            Sound = new Sound();
        }
        public void Key()
        {
            KeySt = Keyboard.GetState();
            
            if (RacePlayer.playerS > 0)
            {
                _city.Move(0, RacePlayer.playerS);
                RacePlayer.playerS -= 0.05f;
            }
            if (RacePlayer.playerS < 0)
            {
                _city.Move(0, RacePlayer.playerS);
                RacePlayer.playerS =0;
            }
            if (KeySt.IsKeyDown(Keys.Enter))
            {
                Sound.CarHorn();
            }
            if (KeySt.IsKeyDown(Keys.Space))
            {
                    Sound.CarScreech();
                    if (RacePlayer.playerS > 0)
                        RacePlayer.playerS -= 1;
                    if (RacePlayer.playerS < 0)
                        RacePlayer.playerS += 1;

            }
            if (KeySt.IsKeyDown(Keys.RightShift))
            {
                if ((RacePlayer.playerS < RacePlayer.MaxSpeed) && (RacePlayer.Nitrous > 0)) 
                {
                    RacePlayer.playerS += 6;
                    RacePlayer.Nitrous--;
                }
            }
            
            if (KeySt.IsKeyDown(Keys.Up))
            {
                if (RacePlayer.playerS < RacePlayer.MaxSpeed)
                    RacePlayer.playerS += 0.1f;
                _city.Move(0, RacePlayer.playerS);
            }

            if (KeySt.IsKeyDown(Keys.Down))
            {
                if (RacePlayer.playerS > -RacePlayer.MaxSpeed)
                    RacePlayer.playerS -= 0.1f;
                _city.Move(0, RacePlayer.playerS);
            }
            if (KeySt.IsKeyDown(Keys.Right))
            {
                if (RacePlayer.playerS>1)
                    _player.Move(10, 0);
            }
            if (KeySt.IsKeyDown(Keys.Left))
            {
                if (RacePlayer.playerS > 1)
                    _player.Move(-10, 0);
            }

            //if (KeySt.IsKeyDown(Keys.Escape))
            //{
            //    _game.graphics.PreferredBackBufferWidth = 800;
            //    _game.graphics.PreferredBackBufferHeight = 500;
            //    _game.graphics.IsFullScreen = false;
            //    _game.graphics.ApplyChanges();
            //}

            //if (KeySt.IsKeyDown(Keys.RightAlt))
            //{
            //    if (KeySt.IsKeyDown(Keys.Enter))
            //    {
            //        _game.graphics.PreferredBackBufferWidth = _game.graphics.GraphicsDevice.DisplayMode.Width;
            //        _game.graphics.PreferredBackBufferHeight = _game.graphics.GraphicsDevice.DisplayMode.Height;
            //        _game.graphics.IsFullScreen = true;
            //        _game.graphics.ApplyChanges();
            //    }
            //}
            Sound.UpdateEngine();
        }
    }
}
